#ifndef __LIB_SENSOR_ENGINE_H__
#define __LIB_SENSOR_ENGINE_H__

#define PREVIEW_SRC_FRONT	0
#define PREVIEW_SRC_REAR	1
#define PREVIEW_SRC_TOTAL	2

typedef enum
{
	PREVIEW_AP_MODE_RECORD,
	PREVIEW_AP_MODE_CAPTURE,
	PREVIEW_AP_MODE_TOTAL
} PREVIEW_AP_MODE;

typedef enum
{
	//show front image only
	PREVIEW_MODE_FRONT,

	//show rear image only
	PREVIEW_MODE_REAR,

	//front image plus a PIP rear image
	PREVIEW_MODE_PIP_REAR,

	//rear image plus a PIP front image
	PREVIEW_MODE_PIP_FRONT,

	//divided to 2 horizontal windows
	PREVIEW_MODE_PBP,

	//show nothing
	PREVIEW_MODE_NONE,

	//painting back a car lines on rear image
	PREVIEW_MODE_BACK,

	//preview is waiting stop
	PREVIEW_MODE_STOP_WAIT,

	//preview is stopped
	PREVIEW_MODE_STOP,

	//a special action to perform mode switching
	PREVIEW_ACT_SWITCH
} PREVIEW_MODE;

//number of normal preview mode
#define PREVIEW_MODE_TOTAL	(1 + PREVIEW_MODE_PBP)

//number of valid preview mode
#define PREVIEW_MODE_VALID	(1 + PREVIEW_MODE_BACK)

//number of preview related action
#define PREVIEW_ACT_TOTAL	(1 + PREVIEW_ACT_SWITCH)

typedef struct VID_REC_ARGS_S
{
	INT32U	sensor_width;
	INT32U	sensor_height;
	INT32U	vid_rec_fifo_total_count;	// total count
	INT32U	vid_rec_fifo_count_idx;
	INT32U	vid_rec_fifo_line_len;
	INT32U	vid_rec_fifo_data_size;
	INT32U	vid_timestamp_start_idx;
	INT32U	vid_timestamp_end_idx;
	INT32U (*fifo_ready_notify) (INT32U fifoMsg, INT32U fifoAddrs, INT32U fifoIdx);
	INT32U (*fifo_buffer_addrs_get) (void);
	INT32S (*fifo_buffer_addrs_put) (INT32U addr);
}

VID_REC_ARGS;

typedef struct SCALER_ARG_S_FIFO
{
	INT32U	scaler_id;
	INT32U	scaler_in_width;
	INT32U	scaler_in_height;
	INT32U	scaler_out_width;
	INT32U	scaler_out_height;
	INT32U	scaler_in_buf[2];
	INT32U	scaler_in_fifo_idx;
	INT32U	scaler_in_fifo_line;
	INT32U	scaler_in_fifo_num;
	INT32U	scaler_in_format;
	INT32U	scaler_out_buf;
	INT32U	scaler_out_fifo_line;
	INT32U	scaler_out_format;
	INT32U	(*scaler_ready_notify) (INT32U fifoMsg, INT32U fifoAddrs);
} SCALER_ARG_FIFO;

typedef struct SCALER_ARG_S
{
	INT32U	scaler_in_width;
	INT32U	scaler_in_height;
	INT32U	scaler_out_width;
	INT32U	scaler_out_height;
	INT32U	scaler_in_buffer_addrs;
	INT32U	scaler_out_buffer_addrs;
	INT32U	scaler_fifo_count;
	INT32U	scaler_output_format;
	INT32U (*scaler_ready_notify) (INT32U fifoMsg, INT32U fifoAddrs);
}

SCALER_ARG;

typedef struct IMG_CAPTURE_ARGS_S
{
	INT32S		jpeg_file_handle;
	SCALER_ARG	scaler_args;
} IMG_CAPTURE_ARGS;

#define SCALER_BUF_A_DONE	0x01
#define SCALER_BUF_B_DONE	0x02

extern INT8U	scalerOutputStatus;
extern INT8U	scalerOutputStatus_rear;

extern const INT8U black_jpg_720p[];
extern const INT32U black_jpg_len_720p;
extern const INT8U black_jpg_vga[];
extern const INT32U black_jpg_len_vga;
extern INT32U black_jpg;
extern INT32U black_jpg_len;


extern void		sensor_preview_src_format_set(INT32U src, INT32U format);
extern void		sensor_preview_src_pixel_set(INT32U src, INT32U width, INT32U height);
extern void		sensor_preview_zoom_window_set(INT32U src, INT16U width, INT16U height, INT16U w_start, INT16U h_start);
extern void		sensor_preview_zoom_window_get(INT32U src, INT16U *width, INT16U *height, INT16U *w_start, INT16U *h_start);
extern void		sensor_preview_src_drop_half(INT32U src, INT32U en);
extern void		sensor_preview_display_format_set(INT32U format);
extern void		sensor_preview_display_pixel_set(INT32U width, INT32U height, INT32U offset);
extern void		sensor_preview_pip_window_set(INT32U pos_x, INT32U pos_y,INT32U width, INT32U height);
extern INT32S	sensor_preview_ap_mode_set(PREVIEW_AP_MODE mode);
extern INT32S	sensor_preview_mode_set(PREVIEW_MODE mode, INT32U wait);
extern INT32S	sensor_preview_start(void);
extern INT32S	sensor_preview_stop(INT32U free);
extern INT32S	sensor_preview_uninit(void);
extern INT32S	sensor_preview_init(INT16U buf_cnt);
extern PREVIEW_MODE sensor_preview_status_get(void);

extern void front_slide_step_value_set(INT16U step_value); //step value should be less than h_start in tft_zoom_parm table
extern INT32S front_vpos_up_adjust(void);
extern INT32S front_vpos_down_adjust(void);

extern void rear_slide_step_value_set(INT16U step_value); //step value should be less than h_start in tft_zoom_parm_r table
extern INT32S rear_vpos_up_adjust(void);
extern INT32S rear_vpos_down_adjust(void);

extern void front_slide_x_step_value_set(INT16U step_value); //step value should be less than w_start in tft_zoom_parm table
extern INT32S front_xpos_left_adjust(void);
extern INT32S front_xpos_right_adjust(void);

extern void rear_slide_x_step_value_set(INT16U step_value); //step value should be less than w_start in tft_zoom_parm_r table
extern INT32S rear_xpos_left_adjust(void);
extern INT32S rear_xpos_right_adjust(void);

extern INT32U sensor_record_statue_get_front(void);
extern INT32U sensor_record_statue_get_rear(void);

extern void		sensor_record_start_front(VID_REC_ARGS *pVidRecArgs);
extern void		sensor_record_start_rear(VID_REC_ARGS *pVidRecArgs);
extern void		sensor_record_stop(void);
extern void		sensor_record_stop_flush(void);
extern INT32S	sensor_capture_start_front(IMG_CAPTURE_ARGS *pImgCaptureArgs);
extern INT32S	sensor_capture_start_rear(IMG_CAPTURE_ARGS *pImgCaptureArgs);

extern INT32U	record_continue_get(void);
extern INT32S	capture_frame_buffer_wait_finish(void);
extern void		capture_scale_start_front(SCALER_ARG *pScaleArgs);
extern void		capture_scale_start_rear(SCALER_ARG *pScaleArgs);
extern void		preview_slide_step_h_set(INT16U step, INT16U step_max);

#endif // __LIB_SENSOR_ENGINE_H__
